import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report

# 示例数据集：包含性别和某些特征
data = {
    'gender': ['male', 'female', 'male', 'female', 'male', 'female'],
    'feature1': [1, 0, 1, 1, 0, 0],
    'feature2': [0, 1, 0, 1, 1, 0],
    'label': [1, 0, 1, 0, 1, 0]
}

df = pd.DataFrame(data)

# 分割数据集
X = df[['feature1', 'feature2']]
y = df['label']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 训练模型
model = LogisticRegression()
model.fit(X_train, y_train)

# 预测
y_pred = model.predict(X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))
print("Classification Report:\n", classification_report(y_test, y_pred))

# 检测性别偏见
male_data = df[df['gender'] == 'male']
female_data = df[df['gender'] == 'female']
male_accuracy = accuracy_score(male_data['label'], model.predict(male_data[['feature1', 'feature2']]))
female_accuracy = accuracy_score(female_data['label'], model.predict(female_data[['feature1', 'feature2']]))

print("Male Accuracy:", male_accuracy)
print("Female Accuracy:", female_accuracy)